<?php
/**
 * Created by PhpStorm.
 * User: trisatria
 * Date: 1/7/14
 * Time: 11:00 AM
 */

namespace Admin\Model;

use Zend\InputFilter\Factory as InputFactory;
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\InputFilterAwareInterface;
use Zend\InputFilter\InputFilterInterface;

class AdminFriends
{
    public $id;
    public $user_id;
    public $friend_id;
    public $follow;
    public $name;
    public $email;
    public $avatar;


    public function exchangeArray($data)
    {
        $this->id     = (isset($data['id'])) ? $data['id'] : null;
        $this->user_id = (isset($data['user_id'])) ? $data['user_id'] : null;
        $this->friend_id  = (isset($data['friend_id'])) ? $data['friend_id'] : null;
        $this->follow     = (isset($data['follow'])) ? $data['follow'] : null;
        $this->name     = (isset($data['name'])) ? $data['name'] : null;
        $this->email     = (isset($data['email'])) ? $data['email'] : null;
        $this->avatar     = (isset($data['avatar'])) ? $data['avatar'] : null;
    }

    //form use
    public function getInputFilter()
    {
        if (!$this->inputFilter) {
            $inputFilter = new InputFilter();
            $factory     = new InputFactory();

            $inputFilter->add($factory->createInput(array(
                'name'     => 'id',
                'required' => false,
            )));

            $inputFilter->add($factory->createInput(array(
                'name'     => 'name',
                'required' => false,
            )));

            $inputFilter->add($factory->createInput(array(
                'name'     => 'email',
                'required' => false,
            )));

            $inputFilter->add($factory->createInput(array(
                'name'     => 'address',
                'required' => false,


            )));

            $inputFilter->add($factory->createInput(array(
                'name'     => 'phone',
                'required' => false,

            )));

            $inputFilter->add($factory->createInput(array(
                'name'     => 'avatar',
                'required' => false,

            )));

            $inputFilter->add($factory->createInput(array(
                'name'     => 'password',
                'required' => false,

            )));


            $inputFilter->add($factory->createInput(array(
                'name'     => 'status',
                'required' => true,

            )));

            $inputFilter->add($factory->createInput(array(
                'name'     => 'user_type',
                'required' => true,

                /*
                'validators' => array(
                    array(
                        'name'    => 'StringLength',
                        'options' => array(
                            'encoding' => 'UTF-8',
                            'min'      => 1,
                            'max'      => 100,
                        ),
                    ),
                ),*/
            )));

            $this->inputFilter = $inputFilter;
        }

        return $this->inputFilter;
    }

    function validateUserFields($postData){
        $result['pass'] = false;
        if (empty ($postData['password'])) $result['message'] = 'Không được bỏ trống mật khẩu';
        if ($postData['password'] != $postData['r_password']) $result['message'] = 'Nhập lại mật khẩu không chính xác';
        if (!isset ($result['message']) || empty ($result['message'])) $result['pass'] = true;
        return $result;
    }

}